package com.example.smartcity.net;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import com.example.smartcity.LoginActivity;
import com.example.smartcity.MainActivity;
import com.example.smartcity.R;

import java.util.HashMap;
import java.util.Map;

public class HttpTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_http_test);


    }

    public void Test(View view) {
        OkhttpHelper okhttpHelper = new OkhttpHelper();
        HashMap<String, String> map = new HashMap<>();

        map.put("username", "dzy123");
        map.put("password", "123456");

        try {
            okhttpHelper.post(
                    map,
                    "http://124.93.196.45:10002/login",
                    this,
                    (MyHttpCallBack<LoginBean>) (data, json) -> {
                        String token = data.getToken();
                        SharedPreferences sp= HttpTestActivity.this.getPreferences(0);
                        SharedPreferences.Editor editor=sp.edit();
                        editor.putString("token",token);
                        editor.commit();
                        startActivity(new Intent(HttpTestActivity.this, MainActivity.class));
                    },LoginBean.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}